package mylab.demo.usm.biz.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import mylab.annotation.rds.ColumnComment;
import mylab.commons.web.mvc.entity.BaseLinkEntity;
import mylab.starters.mybatis.handler.BaseEnumTypeHandler;
import mylab.starters.mybatis.handler.CommaToListTypeHandler;
import mylab.starters.mybatis.interceptor.impl.foreignKey.ForeignKey;
import mylab.usm.api.enums.DataScopeType;

import java.util.List;

/**
 * 角色数据权限表
 */
@Getter
@Setter
@ApiModel("角色数据权限表")
@TableName(autoResultMap = true)
public class SysRoleDataPermission extends BaseLinkEntity<SysRole, SysResource> {

    @ForeignKey(SysRole.class)
    @ColumnComment("角色id")
    @ApiModelProperty(value = "角色id")
    @TableField
    private String roleId;

    @ForeignKey(SysResource.class)
    @ColumnComment("依赖的资源id")
    @ApiModelProperty(value = "依赖的资源id", notes = "对应的资源必须是查询类操作")
    @TableField
    private String dependedResourceId;

    @ColumnComment("业务数据表")
    @ApiModelProperty(value = "业务数据表")
    @TableField
    private String dataTable;

    @ColumnComment("数据权限需要排除的字段")
    @ApiModelProperty(value = "数据权限需要排除的字段")
    @TableField(typeHandler = CommaToListTypeHandler.class)
    private List<String> excludeColumns;

    @ColumnComment("数据权限需要保留的字段")
    @ApiModelProperty(value = "数据权限需要保留的字段")
    @TableField(typeHandler = CommaToListTypeHandler.class)
    private List<String> includeColumns;

    @ColumnComment("数据权限类型")
    @ApiModelProperty(value = "数据权限类型")
    @TableField(typeHandler = BaseEnumTypeHandler.class)
    private DataScopeType dataScopeType;

    @ColumnComment("自定义数据权限类型的sql表达式")
    @ApiModelProperty(value = "自定义数据权限类型的sql表达式")
    @TableField
    private String customExpression;


    @Override
    protected String getLeftId() {
        return roleId;
    }

    @Override
    protected String getRightId() {
        return dependedResourceId;
    }

}
